// pages/cat_mse_look/cat_birth.js
var app = getApp()
const date = new Date()
const years = []
const months = []
const days = []
for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}
for (let i = 1; i <= 12; i++) {
  months.push(i)
}
for (let i = 1; i <= 31; i++) {
  days.push(i)
}
var that
Page({
  data: {
    years: years,
    year: date.getFullYear(),
    months: months,
    month: 1,
    days: days,
    day: 1,
    value: [9999, 0, 0],

    cat_birth: date.getFullYear()+"-"+"1-1",
    cat_id:"",
  },
  onLoad: function (options) {
    that = this;
    this.setData({cat_id: options.id });
  },
  onReady: function () {
  
  },
  onShow: function () {
  
  },
  cat_birthday: function (e) {//选择猫咪生日改变触发的函数
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]]
    })
    this.setData({ cat_birth: this.data.years[val[0]] + "-" + this.data.months[val[1]] + "-" + this.data.days[val[2]] })
  },
  next:function(){
    var n_year = date.getFullYear()
    var n_month = date.getMonth() + 1
    var n_day = date.getDate()
    if ((n_year - that.data.year) * 12 * 365 + (n_month - that.data.month) * 30 + (n_day - that.data.day) < 0) {
      //猫还没生下来呢
      app.toast_up("日期无效")
      return
    } else {
      app.update_cat_msg("birthday", that.data.cat_birth, that.data.cat_id);
      wx.navigateBack({  //返回上一级
        delta: 1
      })
    }


   
  }
})